import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:sp_util/sp_util.dart';

import 'app_pages.dart';

class RouteAuthMiddleware extends GetMiddleware {
  RouteAuthMiddleware({required int priority}) : super(priority: priority);

  @override
  RouteSettings? redirect(String? route) {
    var isLogin = SpUtil.getBool("isLogin");
    if (isLogin == null || !isLogin) {
      Future.delayed(Duration(seconds: 1), () => Get.snackbar("提示", "请先登录APP"));
      return RouteSettings(name: Routes.LOGIN);
    } else {
      return null;
    }
  }
}
